package net.danielseidl.ludumdare.ld48.character;

import java.util.Random;

import net.danielseidl.ludumdare.ld48.level.Level;

/**
 * Representation of a monster character.
 *
 * @author    Daniel Seidl - info@daniel-seidl.net
 */
public class Monster extends Character
	{	
	private boolean walk = true;
	
	/**
	 * Creates a new monster.
	 * @param level The level instance to use.
	 */
	public Monster(int[] location, Level level, SpeedType speed, String image)
		{
		super(location, level, speed, image);
		this.start();
		}
	
	public void stopWalk()
		{
		this.walk = false;
		}

	/**
	 * Moves the monster around.
	 */
	@Override
	public void run()
		{
		Random r = new Random();
		
		int redo = 0;
		MoveDirection redoDir = MoveDirection.UP;
		
		while (this.walk)
			{			
			try 
				{
				Thread.sleep(75);
				}
			catch (InterruptedException e)
				{
				}
			
			if (redo == 0)
				{
				redo++;
				switch(r.nextInt(4))
					{
					case 0:
						this.moveCharacter(MoveDirection.UP);
						redoDir = MoveDirection.UP;
						break;
					case 1:
						this.moveCharacter(MoveDirection.DOWN);
						redoDir = MoveDirection.DOWN;
						break;
					case 2:
						this.moveCharacter(MoveDirection.LEFT);
						redoDir = MoveDirection.LEFT;
						break;
					case 3:
						this.moveCharacter(MoveDirection.RIGHT);
						redoDir = MoveDirection.RIGHT;
						break;
					}
				}
			else
				{
				redo++;
				this.moveCharacter(redoDir);
				if (redo >= 14)
					{
					redo = 0;
					}
				}
			}
		}	
	}